﻿using System;
using System.Data;
using visinia.SmartEngine.Providers;

namespace viWiki.Providers
{
    public abstract partial class viWikiDataProvider    
    {
        #region INIT
        private static viWikiDataProvider _provider;
        private static object _lock = new object();

        public static viWikiDataProvider Provider
        {
            get { InternalInitialize(); return _provider; }
        }
        private static void InternalInitialize()
        {
            if (_provider == null)
            {
                lock (_lock)
                {
                    if (_provider == null)
                    {
                        _provider = (viWikiDataProvider)ProviderController.CreateDataProvider("viWiki");
                        if (_provider == null)
                            throw new Exception("Unable to load default viWikiDataProvider");
                    }
                }
            }
        }
        #endregion

        #region WikiPages
        public abstract IDataReader GetWikiPages();
        public abstract IDataReader AddWikiPage(int NamespaceInfoId, string Name, string Content, DateTime Date, string Author, string Url);
        public abstract void UpdateWikiPage(int WikiPageId, int NamespaceInfoId, string Name, string Content, DateTime Date, string Author, string Url);
        public abstract void DeleteWikiPage(int WikiPageId);
        #endregion

        #region WikiSettings
        public abstract IDataReader GetWikiSettings();
        public abstract void AddWikiSetting(string key, string value);
        public abstract void UpdateWikiSetting(string key, string value);
        public abstract void DeleteWikiSetting(string key);
        #endregion

        #region Namespaces
        public abstract IDataReader GetNamespaces();
        public abstract IDataReader AddNamespace(string Name, int DefaultWikiPageId);
        public abstract void UpdateNamespace(int NamespaceInfoId, string Name, int DefaultWikiPageId);
        public abstract void DeleteNamespace(int NamespaceInfoId);
        #endregion

        #region WIKI PAGE LINKS
        public abstract IDataReader GetWikiPageLinks();
        public abstract void AddWikiPageLink(int SourceWikiPageId, int DestinationWikiPageId);
        public abstract void DeleteWikiPageLinks(int SourceWikiPageId);
        #endregion        
    }
}
